<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
        <title>登陆成功</title>
        <script type="text/javascript" src="${pageContext.request.contextPath}/static/bootstrap/js/jquery.min.js"></script>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/static/bootstrap/css/bootstrap.css">
        <script type="text/javascript" src="${pageContext.request.contextPath}/static/bootstrap/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/static/bootstrap/js/docs.min.js"></script>

        <script type="text/javascript" src="../../static/bootstrap/js/jquery.min.js"></script>
        <script type="text/javascript" src="../../static/bootstrap/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="../../static/bootstrap/js/docs.min.js"></script>
        <link rel="stylesheet" href="../../static/bootstrap/css/bootstrap.min.css">
        <style>
            .btn-w100 {
                width: 100%;
                color: #3981e2;
            }

        </style>
    </head>

    <body>
        <div class="container-fluid">
            <div class="row">
                <div class="pull-right" id="nowtime"></div>
            </div>
            <div class="row">
                <div class="pull-right">${existUser},您好!</div>
            </div>

            <div class="row">
                <div class="col-md-2 div-left">
                    <div class="panel-group" id="accordion" aria-multiselectable="true">
                        <a class="btn btn-default btn-full btn-w100" data-toggle="collapse" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne">药品管理 <span class="glyphicon glyphicon-th-list pull-right" aria-hidden="true" ></span></a>
                        <div id="collapseOne" class="panel-collapse collapse">
                            <div class="list-group">
                                <a href="javascript:getBcdrug();" class="list-group-item">药品目录</a>
                                <a href="#" class="list-group-item">药品进货</a>
                                <a href="#" class="list-group-item">药品出库</a>
                            </div>
                        </div>
                        <a class="btn btn-default btn-full btn-w100" data-toggle="collapse" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">库存管理 <span class="glyphicon glyphicon-th-list pull-right" aria-hidden="true" ></span></a>
                        <div id="collapseTwo" class="panel-collapse collapse">
                            <div class="list-group">
                                <a href="#" class="list-group-item">库存目录</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-8 div-center">
                    <table class="table table-hover table-bordered table-responsive" id="grid_drug">

                    </table>
                </div>
                <div class="col-md-2 div-right">

                </div>
            </div>
        </div>
        <script>
            function getBcdrug() {
                $.ajax({
                    url: "${pageContext.request.contextPath}/bcdrug/page",
                    data: "pn=1",
                    type: "GET",
                    success: function(result) {
                        var result = eval('(' + result + ')');
                        console.log(result);
                        if (100 == result.code)
                            build_drug_table(result);
                    }
                });
            }

            function build_drug_table(result) {
                $("#grid_drug").empty();
                var caption = $("<caption></caption>").append("<h4>药品清单</h4>").appendTo("#grid_drug");
                var hName = $("<th></th>").append("名称");
                var hLoginName = $("<th></th>").append("编码");
                var hType = $("<th></th>").append("种类");
                $("<tr></tr>").append("<th>#</th>").append(hName).append(hLoginName).append(hType).append("<th></th>").appendTo("#grid_drug");
                var drugs = result.extend.pageInfo.list;
                $.each(drugs, function(index, item) {
                    var checkBoxTd = $("<td><input type='checkbox' class='check_item'/></td>");
                    var name = $("<td></td>").append(item.name);
                    var code = $("<td></td>").append(item.code);
                    var drugType = $("<td></td>").append(item.drugType);

                    //为编辑按钮添加一个自定义的属性,来表示当前员工的id
                    var editBtn = $("<button></button>").addClass("btn btn-primary btn-sm edit_btn").append($("<span></span>").addClass("glyphicon glyph icon-pencil")).append("编辑");
                    editBtn.attr("edit-id", item.empId);
                    var delBtn = $("<button></button>").addClass("btn btn-danger btn-sm delete_btn").append($("<span></span>").addClass("glyphicon glyphicon-trash")).append("删除");
                    //为删除按钮添加一个自定义的属性来表示当前员工的删除id
                    delBtn.attr("del-id", item.empId);

                    $("<tr></tr>").append(checkBoxTd).append(name).append(code).append(drugType).append(editBtn).append(delBtn).appendTo("#grid_drug");
                });
            }

            setInterval("document.getElementById('nowtime').innerHTML='时间:'+new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());", 0);

        </script>
    </body>

    </html>
